<template>
  <div>

    <el-row>
      <el-col :span="24" id="AdminAccountManagement1">

        <div id="AdminAccountManagement2">
          <el-input v-model="param.adminName" placeholder="请输入姓名" style="width: 20%;"></el-input>
          <el-button type="primary" @click="search" round>搜索</el-button>
        </div>

        <div style="height: 20px;"></div>
        <el-table :data="page.records" border>

          <el-table-column prop="adminId" label="管理员ID" width="90 ">
          </el-table-column>
          <el-table-column prop="adminImage" label="管理员头像" width="130">
            <template #default="scope">
              <img :src="scope.row.adminImage" alt="管理员头像" style="max-width: 110px; max-height: 110px">
            </template>
          </el-table-column>
          <el-table-column prop="adminName" label="用户名" width="110">
          </el-table-column>
          <el-table-column prop="adminPhone" label="手机" width="120">
          </el-table-column>
          <el-table-column prop="adminEmail" label="邮箱" width="170">
          </el-table-column>
          <el-table-column prop="adminState" label="账户状态" width="90">
            <template slot-scope="scope">
              <template v-if="scope.row.adminState == 0">
                冻结
              </template>
              <template v-if="scope.row.adminState == 1">
                正常
              </template>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150">
            <template #default="scope">

              <el-button @click="disableType(scope.row.adminId)" v-if="scope.row.adminState == '1'" type="text"
                size="small">禁用</el-button>
              <el-button @click="enableType(scope.row.adminId)" v-if="scope.row.adminState == '0'" type="text"
                size="small">启用</el-button>

            </template>
          </el-table-column>
        </el-table>

        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="page.pageNum" :page-sizes="[1, 2, 3, 5]" :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="page.total">
        </el-pagination>

      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    name: "AdminAccountManagement",
    data() {
      return {
        page: {},
        param: {
          adminName: "",
          pageNum: 1,
          pageSize: 5,
        },
      }
    },
    methods: {
      //搜索按钮
      search() {
        this.param.pageNum = 1;
        this.loadAllAdmin();
      },
      //启用
      enableType(adminId) {
        this.$http.get("/account/yAdmin/enable", {
          params: {
            adminId: adminId
          }
        }).then(resp => {
          this.$message({
            message: resp.data.msg,
            type: 'success'
          });
          this.loadAllAdmin();
        });
      },
      //禁用
      disableType(adminId) {
        this.$http.get("/account/yAdmin/disable", {
          params: {
            adminId: adminId
          }
        }).then(resp => {
          this.$message({
            message: resp.data.msg,
            type: 'success'
          });
          this.loadAllAdmin();
        });
      },
      //分页
      handleSizeChange(val) {
        this.param.pageSize = val;
        this.loadAllAdmin();
      },
      handleCurrentChange(val) {
        this.param.pageNum = val;
        this.loadAllAdmin();
      },
      //带条件分页查询
      loadAllAdmin() {
        this.$http.get("/account/yAdmin/loadPageAdmin", {
          params: this.param
        }).then(resp => {
          this.page = resp.data.data;
        })
      }
    },
    created() {
      this.loadAllAdmin();
    }
  }
</script>

<style>
  #AdminAccountManagement2 {
    margin-left: -420px;
    line-height: 100%;
    width: 100%
  }

  #AdminAccountManagement1 {
    line-height: 100%;
    width: 100%
  }
</style>
